<template>
	<view class="page">
		<view class="agent-header">
			<view class="top"><text>本月代理点</text><view>{{onList.performance?onList.performance:0}}</view></view>
			<view class="month-nav">
				<view class="item">
					<view class="title">可退取奖励</view><view class="num">{{onList.live_profit?onList.live_profit:0}}</view><view class="time"></view>
				</view>
				<view class="item">
					<view class="title">备用奖励</view><view class="num">{{onList.now_profit?onList.now_profit:0}}</view><view class="time"></view>
				</view>
			</view>
		</view>
		<view class="agent-progress abox">
			<image src="../../static/icons/user/agent_tit.png" class="title"></image>
			<view class="progress-box">
				<view class="text" :style="{color:isActive?'#000000':'#d94b4b'}">{{agent_spot}}</view>
				<progress :percent="now_percent" :activeColor="isActive?'#3fce6a':'#d94b4b'" 
				backgroundColor="#e5e5e5" active stroke-width="16" />
			</view>
			<view class="point-text" @tap="pointTip"><view>本月代理点数变化</view><view class="icon"><image src="../../static/icons/user/warn.png"></image></view></view>
		</view>
			
		<view class="results-list abox">
			<view class="first-item" v-if="isShow == 1">
				<view class="item">
					<text class="num">上个月总业绩</text>
					<view class="user-pic">{{lastList.performance||0}}</view>
				</view>
				<view class="detail-info">
					<view class="detail-info-item">
						<view class="detail-info-item-name">距离达标业绩</view>
						<view class="detail-info-item-red">{{lastList.c_performance||0}}</view>
					</view>
					<view class="detail-info-item">
						<view class="detail-info-item-name">奖励金</view>
						<view class="detail-info-item-green">{{lastList.profit||0}}</view>
					</view>	
					<view class="detail-info-item">
						<view class="detail-info-item-name">作废金</view>
						<view class="detail-info-item-red">{{lastList.z_profit||0}}</view>
					</view>	
				</view>
			</view>
			<view class="item">
				<text class="num">余留业绩点</text>
				<view class="user-pic">{{remaining_spot}}</view>
			</view>
			<view class="item">
				<text class="num">已释放奖励</text>
				<view class="user-pic">{{onList.sparse_release||0}}</view>
			</view>
			<view class="item">
				<text class="num">代理期总奖励</text>
				<view class="user-pic">{{onList.all_profit||0}}</view>
			</view>
			<view class="item" v-if="onList.month_head_profit > 0">
				<text class="num">本月团队长奖励</text>
				<view class="user-pic">{{onList.month_head_profit||0}}</view>
			</view>
			<!-- <view class="item" v-if="onList.all_head_profit > 0">
				<text class="num">团队长总奖励</text>
				<view class="user-pic">{{onList.all_head_profit}}</view>
			</view> -->
		</view>
			<!-- v-for="(item,index) in recordsList" -->
		<view class="mon-results-list abox" v-if="recordsList.length > 0">
			<navigator open-type="navigate" :url="'/pages/user/agent_bill?month=' + item.year_month_title" class="item" v-for="(item,index) in recordsList" :key="index">
				<view class="left">
					<image class="icon" src="../../static/icons/user/profit_icon.png"></image>
					<view class="title">{{item.month_title}}月代理点汇总({{item.month_title+1}}月更新
					)<text class="num">{{item.agent_spot}}</text></view>
				</view>
				<view class="right"><view class="up"></view>释放奖励{{item.free_amount}}</view>
			</navigator> 
			<!-- <view class="more">查看更多<image src="../../static/icons/user/a_more.png"></image></view> -->
		</view>
		<view url="/pages/user/agent_take" class="inter-btn" @tap="togglePopup">代理业绩转出</view>
		
		<view class="g-frame-mask" v-if="showPopup"></view>
		<view class="g-frame" v-if="showPopup">
			<view class="m-frame-header">
			    <view class="u-frame-title">代理业绩转出</view>
			    <image class="u-frame-close" src="../../static/icons/ydt/close.png" mode="widthFix" @tap="togglePopup"></image>
			</view>
			<view class="u-frame-cont">
				<view class="ture-content">
					<view class="title">可转出代理业绩：<text class="num">{{onList.live_profit}}</text></view>
					<view class="input"><input type="number" v-model="nPrice" placeholder="请点击输入转出业绩" /></view>
				</view>
			</view>
			<view class="m-frame-footer">
			    <view class="u-reset" @tap="togglePopup">取消</view>
			    <view class="u-confirm" @tap="confirm">确定</view>
			</view>
		</view>
		
		
		<view class="m-loading" v-if="showLoading">
		    <image src="../../static/images/loading.gif" mode="widthFix"></image>
		    <text>加载中</text>
		</view>
	</view>
</template>

<script>
	import henglang from '@/common/common.js';
	export default {
		data() {
			return {
				recordsList:[],
				onList:[],
				totalList:[],
				nowList:[],
				showLoading: false,
				isActive: true,
				agent_spot:0,
				now_percent:0,
				remaining_spot:0,
				showPopup: false,
				nPrice: '',
				lastList:[],
				isShow: 0
			}
		},
		methods: {
			togglePopup() {
				this.showPopup = !this.showPopup
			},
			confirm() {
				if(this.showLoading==true){
					henglang.showToast('正在加载中')
					return false;
				}
				this.showPopup = !this.showPopup
				this.showLoading = true;
				
				let nPrice=this.nPrice;
				this.nPrice=''
				let that = this;
				
				henglang.post('agent/profit_to_lc',{nPrice:nPrice},true,function(res){
					henglang.showToast(res.data.msg)
					if(res.data.code<=0){
						that.showLoading = false
						return;
					}
					that.loadData()
				})
			},
			loadData(){
				let that = this;
				that.showLoading = true
				//获取收益释放信息
				
				henglang.post('agent/get_profit_info',{},true,function(res){
					that.onList = res.data.data;
					that.lastList = res.data.data.last
					that.isShow = res.data.data.is_show
					henglang.post('agent/get_monthly_earnings',{},true,function(res){
						that.showLoading = false
						if(res.data.code==0){
							that.recordsList = res.data.data
							that.agent_spot=that.recordsList[0]['agent_spot']
							that.now_percent=that.recordsList[0]['percent']
							that.remaining_spot=that.recordsList[0]['remaining_spot']
							
						}
					})
				})
			},
			pointTip() {
				henglang.showToast('每新增1万粮仓，代理点数上升1')
			}
		},
		onReady() {
			this.loadData()
		}
		
	}
</script>

<style>
	/* 图片通用自适应 */
	image{
		width: 100%;
		height: 100%;
	}
	page{
		background: #f5f5f5;
		
	}
	.abox{
		background: #ffffff;
		margin-bottom: 20rpx;
	}
	.agent-header{
		height: 443rpx;
		background-image: url('~@/static/icons/user/agent_hbg.png');
		background-repeat: no-repeat;
		background-size: 100% 100%;
		color: #ffffff;
	}
	.agent-header .top{
		text-align: center;
		padding-top: 75rpx;
	}
	.agent-header .top text{
		font-size: 32rpx;
	}
	.agent-header .top view{
		font-size: 80rpx;
		font-weight: bold;
	}
	.agent-header .top view image{
		width: 48rpx;
		height: 48rpx;
		vertical-align: middle;
		margin-top: -16rpx;
		margin-right: 22rpx;
	}
	.agent-header .month-nav{
		display: flex;
		align-items: center;
		text-align: center;
		width: 100%;
		position: relative;
		margin-top: 30rpx;
	}
	.agent-header .month-nav .item{
		flex: 1;
	}
	.agent-header .month-nav .title{
		font-size: 32rpx;
	}
	.agent-header .month-nav .num{
		font-size: 60rpx;
		font-weight: bold;
		line-height: 80rpx;
	}
	.agent-header .month-nav .time{
		font-size: 28rpx;
		letter-spacing: 4rpx;
	}
	.agent-header .month-nav::after{
		content: '';
		position: absolute;
		top: 50%;
		margin-top: -41rpx;
		left: 50%;
		background: #ffffff;
		width: 2rpx;
		height: 82rpx;
	}
	.agent-progress{
		padding: 46rpx 28rpx 63rpx 28rpx;
		text-align: center;
	}
	.agent-progress .title{
		width: 569rpx;
		height: 50rpx;
	}
	.progress-box{
		position: relative;
		border: 4rpx solid #dddddd;
		border-radius: 20rpx;
		overflow: hidden;
		margin-top: 18rpx;
	}
	.progress-box .text{
		display: flex;
		justify-content: flex-end;
		align-items: center;
		position: absolute;
		top: -4rpx;
		left: 0;
		width: calc(100% - 56rpx);
		color: #ffffff;
		font-size: 28rpx;
		font-style: italic;
		font-weight: bold;
		padding: 0 28rpx;
	}
	.point-text{
		display: flex;
		justify-content: flex-end;
		align-items: flex-start;
		padding-top: 5rpx;
	}
	.point-text .icon{
		width: 26rpx;
		height: 26rpx;
		margin-top: 4rpx;
		margin-left: 5rpx;
	}
	.point-text .icon image{
		width: 100%;
		height: 100%;
	}
	.results-list .item{
		display: flex;
		justify-content: space-between;
		align-items: center;
		position: relative;
		color: #515151;
		font-size: 28rpx;
		padding: 0 50rpx;
		height: 88rpx;
		border-bottom: 2rpx solid #e5e5e5;
	}
	.results-list .item::after{
		content: '';
		position: absolute;
		top: 50%;
		left: 20rpx;
		margin-top: -13rpx;
		width: 26rpx;
		height: 26rpx;
		background-image: url('~@/static/icons/user/a_circle.png');
		background-repeat: no-repeat;
		background-size: 100% 100%;
	}
	.results-list .item:last-child,.results-list .first-item .item{
		border-bottom: 0;
	}
	.results-list .detail-info{
		display: flex;
		justify-content: center;
		text-align: center;
		font-size: 28rpx;
		padding: 20rpx 0;
	}
	.results-list .first-item{
		border-bottom: 2rpx solid #e5e5e5;
	}
	.results-list .detail-info .detail-info-item{
		flex: 1;
	}
	.results-list .detail-info .detail-info-item .detail-info-item-name{
		color: #666666;
	}
	.results-list .detail-info .detail-info-item .detail-info-item-red{
		color: #d94b4b;
	}
	.results-list .detail-info .detail-info-item .detail-info-item-green{
		color: #54d279;
	}
	.mon-results-list{ 
		margin-bottom: 150rpx;
	}
	.mon-results-list .item{
		border-bottom: 2rpx solid #e5e5e5;
		height: 130rpx;
	}
	.mon-results-list .item,.mon-results-list .item .left{
		display: flex;
		justify-content: space-between;
		align-items: center;
	}
	.mon-results-list .item .icon{
		width: 70rpx;
		height: 70rpx;
		margin-right: 22rpx;
		margin-left: 30rpx;
		display: block;
	}
	.mon-results-list .item .title{
		font-size: 30rpx;
		font-weight: bold;
		color: #515151;
		display: block;
		flex: 1;
	}
	.mon-results-list .item .num{
		font-size: 28rpx;
		color: #7c7c7c;
		display: block;
	}
	.mon-results-list .item .right{
		text-align: right;
		margin-right: 50rpx;
		font-size: 30rpx;
	}
	.mon-results-list .item .time{
		color: #a09999;
		font-size: 26rpx;
		padding-top: 4rpx;
	}
	.mon-results-list .item .right image{
		width: 25rpx;
		height: 34rpx;
		margin-right: 6rpx;
	}
	.mon-results-list .item .up{
		color: #3fce6a;
		font-weight: bold;
		vertical-align: top;
	}
	.mon-results-list .item .down{
		color: #d94b4b;
		font-weight: bold;
	}
	.mon-results-list .item .down image{
		vertical-align: middle;
	}
	.mon-results-list .more{
		text-align: center;
		line-height: 90rpx;
		font-size: 30rpx;
		color: #515151;
	}
	.mon-results-list .more image{
		width: 27rpx;
		height: 24rpx;
		margin-left: 15rpx;
	}
	.inter-btn{
		text-align: center;
		color: #ffffff;
		background: #3fce6a;
		width: 100%;
		position: fixed;
		bottom: 0;
		left: 0;
		height: 100rpx;
		line-height: 100rpx;
		font-size: 30rpx;
	}
	.ture-content{
		font-size: 32rpx;
	}
	.ture-content .input{
		padding: 30rpx 0;
	}
	.ture-content .input input{
		width: 99%;
		font-size: 40rpx;
		text-align: center;
		border: 1px solid #828080;
		border-radius: 10rpx;
		padding: 20rpx 0;
	}
	
	.g-frame {
	    width: 581rpx;
	    background: #fff;
	    border-radius: 20rpx;
	    position: fixed;
	    top: 50%;
	    overflow: hidden;
	    left: 50%;
		margin-top: -250rpx;
		margin-left: -290rpx;
		z-index: 12;
	}
	
	.g-frame-mask {
	    background: #000;
	    opacity: .5;
	    height: 100vh;
	    width: 100%;
	    position: fixed;
	    top: 0rpx;
		z-index: 11;
	}
	
	.m-frame-header {
	    height: 110rpx;
	    width: 100%;
	    background: #3fce6a;
	    border-top-right-radius: 20rpx;
	    border-top-left-radius: 20rpx;
		position: relative;
		margin-bottom: 35rpx;
	}
	.u-frame-title {
	    width: 100%;
	    text-align: center;
	    color: #fff;
	    line-height: 110rpx;
	    font-size: 32rpx;
	}
	
	.u-frame-close {
	    width: 42rpx;
	    height: 42rpx;
	    background-size: 100%;
	    position: absolute;
	    top: 50%;
		margin-top: -21rpx;
	    right: 32rpx;
	}
	.u-frame-cont{
		text-align: center;
		font-size: 36rpx;
		padding-bottom: 35rpx;
		line-height: 60rpx;
		width: 500rpx;
		margin: 0 auto;
	}
	.m-frame-footer {
	    height: 100rpx;
	    width: 100%;
	    box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
		display: flex;
		align-items: center;
		margin-top: 20rpx;
	}
	
	.m-frame-footer view {
		flex: 1;
	    line-height: 100rpx;
	    text-align: center;
	    font-size: 32rpx;
	}
	
	.u-reset {
	    color: #000000;
	    background: #fff;
	}
	
	.u-confirm {
	    background: #3fce6a;
	    color: #fff;
	    border-bottom-right-radius: 16rpx;
	}
</style>
